
/*
 * Java class "Coord.java" generated from Poseidon for UML.
 * Poseidon for UML is developed by <A HREF="http://www.gentleware.com">Gentleware</A>.
 * Generated with <A HREF="http://jakarta.apache.org/velocity/">velocity</A> template engine.
 */
package jcs;

import java.lang.String;


/**
 * Coord Class
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7f8f]
 */
public class Coord {

  ///////////////////////////////////////
  // attributes


/**
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fd9]
 */
    private double x; 

/**
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fd8]
 */
    private double y; 

/**
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fd7]
 */
    private final double DEFAULT_TOLERANCE = 10.0; 


  ///////////////////////////////////////
  // operations


/**
 * 
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fd6]
 * @return 
 */
    public  Coord() {        
        		x =  0.0;
        		y =  0.0;
    } // end Coord        

/**
 * 
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fd5]
 * @return 
 * @param x 
 * @param y 
 */
    public  Coord(double x, double y) {        
        		this.x = x;
        		this.y = y;
    } // end Coord        

/**
 * 
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fd4]
 * @return 
 * @param in 
 */
    public  Coord(Coord in) {        
        		this.x = in.getX();
        		this.y = in.getY();
    } // end Coord        

/**
 * 
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fd3]
 * @return 
 */
    public double getX() {        
        		return x;
    } // end getX        

/**
 * 
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fd2]
 * @return 
 */
    public double getY() {        
        		return y;
    } // end getY        

/**
 * 
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fd1]
 * @param x 
 */
    public void setX(double x) {        
        		this.x = x;
    } // end setX        

/**
 * 
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fd0]
 * @param y 
 */
    public void setY(double y) {        
        		this.y = y;
    } // end setY        

/**
 * 
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fcf]
 * @param _x 
 * @param _y 
 */
    public void setXY(double _x, double _y) {        
        		this.setX( _x );
        		this.setY( _y );
    } // end setXY        

/**
 * 
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fce]
 * @return 
 * @param enemyBearing 
 * @param enemyDistance 
 */
    public Coord getCoordFromScan(double enemyBearing, double enemyDistance) {        
        		double _x, _y;
        		if(enemyBearing <= (Math.PI /  2.0))
        		{
        			_x = x + enemyDistance * Math.sin(enemyBearing);
        			_y = y + enemyDistance * Math.cos(enemyBearing);			
        		}
        		if(enemyBearing <= Math.PI && enemyBearing > (Math.PI /  2.0))
        		{
        			_x = x + enemyDistance * Math.sin(Math.PI - enemyBearing);
        			_y = y - enemyDistance * Math.cos(Math.PI - enemyBearing);			
        		}
        		if(enemyBearing > Math.PI && enemyBearing <=  3.0 * Math.PI /  2.0)
        		{
        			_x = x - enemyDistance * Math.sin(enemyBearing - Math.PI);
        			_y = y - enemyDistance * Math.cos(enemyBearing - Math.PI);			
        		}
        		else
        		{
        			_x = x - enemyDistance * Math.sin( 2.0 * Math.PI - enemyBearing);
        			_y = y + enemyDistance * Math.cos( 2.0 * Math.PI - enemyBearing);			
        		}
        		Coord out = new Coord(_x, _y);
        		return out;
    } // end getCoordFromScan        

/**
 * 
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fcd]
 * @return 
 * @param in 
 */
    public boolean equals(Coord in) {        
        		boolean answer = false;
        		if( ( Math.abs( in.getX() - x ) < DEFAULT_TOLERANCE ) &&
        		    ( Math.abs( in.getY() - y ) < DEFAULT_TOLERANCE ) )
        		{
        			answer = true;
        		}
        		
        		return answer;
    } // end equals        

/**
 * 
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fcc]
 * @return 
 */
    public String toString() {        
        		return new String( "(" + x + "," + y +")");
    } // end toString        

/**
 * 
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fcb]
 * @return 
 * @param _target 
 */
    public double calcHeading(Coord _target) {        
        		double heading;
        		double hyp = this.calcDist( _target );
        		double x = ( _target.getX() - this.getX() );
        		double y = ( _target.getY() - this.getY() );
        		// Should test if 'hyp' is zero before divide.
        		// But 'hyp' is a double. Can't use if( hyp == 0 )
        		
        		
        		if( x >  0.0 && y >  0.0 )
        		{
        			heading = Math.abs( Math.asin( x/hyp ));
        		}
        		else if( x >  0.0 && y <  0.0 )
        		{
        			heading = (Math.PI/ 2.0) + Math.abs( Math.asin( y/hyp ));
        		}
        		else if( x <  0.0 && y <  0.0 )
        		{
        			heading = (Math.PI) + Math.abs( Math.asin( x/hyp ));
        		}
        		else // if( x < 0.0 && y > 0.0 )
        		{
        			heading = (3 * Math.PI /  2.0) + Math.abs( Math.asin( y/hyp ));			
        		}
        		
        		return heading;
    } // end calcHeading        

/**
 * 
 * 
 * @poseidon-object-id [sm$89848d:ffe131bfd5:-7fca]
 * @return 
 * @param _target 
 */
    public double calcDist(Coord _target) {        
        		double dist = 0;
        		
        		// Don't worry about negative or positive signs. Will be squared later.
        		double x = ( this.getX() - _target.getX() );
        		double y = ( this.getY() - _target.getY() );
        		
        		dist = Math.sqrt( x*x + y*y );
        		
        		return dist;
    } // end calcDist        

/**
 * <p>Does ...</p>
 * 
 * @poseidon-object-id [sm$3cc05f:ffee92588c:-7e5c]
 * @return 
 * @param _coord 
 */
    public Coord minus(Coord _coord) {        
        return new Coord(_coord.getX() - x, _coord.getY() - y);
    } // end minus        

/**
 * <p>Does ...</p>
 * 
 * @poseidon-object-id [sm$3cc05f:ffee92588c:-7e59]
 * @return 
 * @param _coord 
 */
    public Coord plus(Coord _coord) {        
        return new Coord(_coord.getX() + x, _coord.getY() + y);
    } // end plus        

 } // end Coord


